﻿using System;
using System.Collections.Generic;
using System.Web.Mvc.Html;
using ControleRepresentante.Logic.Models;
using WebSite.ViewModels.Fields;

namespace WebSite.ViewModels.IndexViewModels
{
    public static class FabricaIndexColumns
    {
        public static Guid Nome = new Guid("207f1dc2-e2ab-481a-92e0-dfe08ba82c3c");
        public static Guid CNPJ = new Guid("307f1dc2-e2ab-481a-92e0-dfe08ba82c3c");
        public static Guid InscricaoEstadual = new Guid("407f1dc2-e2ab-481a-92e0-dfe08ba82c3c");
    }

    public class FabricaIndexViewModel : UsuariosHolderIndexViewModel<Fabrica>
    {
        public FabricaIndexViewModel(bool canCreatePedido)
            : base("Fábricas", canCreatePedido)
        {
        }

        public string NomeBuscaValue { get; set; }

        protected override void RegisterColumns(IndexColumnDefinitionsCollectionWrapper<Fabrica> indexColumnDefinitionsCollectionWrapper)
        {
            indexColumnDefinitionsCollectionWrapper.Register(FabricaIndexColumns.Nome, (fabrica, htmlHelper) => htmlHelper.ActionLink(fabrica.Nome, "Details", new { id = fabrica.Id }));
            indexColumnDefinitionsCollectionWrapper.Register(FabricaIndexColumns.CNPJ, x => x.CNPJ);
            indexColumnDefinitionsCollectionWrapper.Register(FabricaIndexColumns.InscricaoEstadual, x => x.InscricaoEstadual);
            base.RegisterColumns(indexColumnDefinitionsCollectionWrapper);
        }

        protected override IEnumerable<IField> GetSearchFields()
        {
            List<IField> result = new List<IField>
            {
                new TextBoxField("Nome", "nome", NomeBuscaValue)
            };

            result.AddRange(base.GetSearchFields());
            return result;
        }
    }
}